﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOAModels;
using TarreOA.TarreOABLL;

public partial class PublicCommunication_EditComGroupInfo : System.Web.UI.Page
{
    private int cg_id;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString.Get("pcg_id") != null)
            {
                cg_id = int.Parse(Request.QueryString.Get("pcg_id"));
                this.FindComGroupInfoForDisplay();
                ViewState["cg_id"] = cg_id;
            }
        }
    }

    /// <summary>
    /// 查找指定编号分组信息并显示
    /// </summary>
    protected void FindComGroupInfoForDisplay()
    {
        PublicCommunicationGroupService pcgService = new PublicCommunicationGroupService();
        PublicCommunicationGrouptb pcg = pcgService.findById(cg_id);
        if (pcg != null)
        {
            this.LblGroupName.Text = pcg.PcgName;
            this.LblGroupCreateTime.Text = pcg.PcgCreateTime.ToString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (ViewState["cg_id"] != null)
        {
            cg_id = (int)ViewState["cg_id"];
        }
        string newName = Request.Form.Get(this.TxtNewGroupName.ClientID);
        if(!"".Equals(newName.Trim()))
        {
            PublicCommunicationGroupService pcgService = new PublicCommunicationGroupService();
            if (pcgService.updateGroupInfoById(cg_id, newName, DateTime.Now) == 1)
            {
                ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "window.parent.leftFrame.location.reload();", true);
                //Response.Redirect("ComGroupManager.aspx");
                this.FindComGroupInfoForDisplay();
                this.TxtNewGroupName.Text = "";
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('更新失败，请重试！');", true);
            }
        }
    }
}
